package com.kujie.access.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kujie.access.domain.query.PolicySubmitInformationQuery;
import com.kujie.access.domain.vo.PolicySubmitInformationExportImportVO;
import com.kujie.access.domain.vo.PolicySubmitInformationVO;
import com.kujie.access.service.IPolicySubmitInformationService;
import com.kujie.common.core.domain.R;
import com.kujie.common.encrypt.annotation.ApiEncrypt;
import com.kujie.common.excel.utils.ExcelUtil;
import com.kujie.common.mybatis.core.page.PageQuery;
import com.kujie.common.web.core.BaseController;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 政策申报信息 controller
 *
 * @author check
 * @date 2025-07-03
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/policySubmit")
@ApiEncrypt(response = true)
public class PolicySubmitInformationController extends BaseController {
    private final IPolicySubmitInformationService policySubmitInformationService;

    /**
     * 获取列表
     */
    @GetMapping("/list")
    public R<Page<PolicySubmitInformationVO>> list(PolicySubmitInformationQuery policySubmitInformationQuery, PageQuery pageQuery) {
        return R.ok(policySubmitInformationService.list(policySubmitInformationQuery, pageQuery));
    }

    /**
     * 获取详情
     */
    @GetMapping("/detail")
    public R<PolicySubmitInformationVO> detail(String companyUUID) {
        return policySubmitInformationService.detail(companyUUID);
    }

    /**
     * 新增或修改
     */
    @PostMapping("/insertOrUpdate")
    public R<?> insertOrUpdate(@RequestBody PolicySubmitInformationVO policySubmitInformationVO) {
        return toAjax(policySubmitInformationService.insertOrUpdate(policySubmitInformationVO));
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/{ids}")
    public R<?> batchDelete(@PathVariable List<String> ids) {
        return toAjax(policySubmitInformationService.batchDelete(ids));
    }

    /**
     * 批量导出
     */
    @PostMapping("/batchExport")
    public void batchExport(@RequestBody PolicySubmitInformationQuery policySubmitInformationQuery, HttpServletResponse response) {
        List<PolicySubmitInformationExportImportVO> policySubmitInformationExportImportVOS = policySubmitInformationService.batchExport(policySubmitInformationQuery, response);
        ExcelUtil.exportExcel(policySubmitInformationExportImportVOS, "政策申报信息列表", PolicySubmitInformationExportImportVO.class, response);
    }

    /**
     * 批量导入
     */
    @PostMapping("/batchImport")
    public R<?> batchImport(@RequestPart("file") MultipartFile file) throws Exception {
        return toAjax(policySubmitInformationService.batchImport(file));
    }

    /**
     * 导出模板
     */
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(CollectionUtil.newArrayList(), "政策申报信息模板", PolicySubmitInformationExportImportVO.class, response);
    }
}
